#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int triangleNumber(vector<int>& nums)
    {
        sort(nums.begin(), nums.end());
        int max = nums.size() - 1;
        int count = 0;
        while (max >= 2)
        {
            int l = 0, r = max - 1;
            while (l < r)
            {
                if (nums[l] + nums[r] > nums[max]) count += r - l, r--;
                else l++;
            }
            max--;
        }
        return count;
    }
};